home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / pascal / playmid.exe / MIDI.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-03-18  |  3.3 KB  |  74 lines

  1. {*******************************************************************************
  2.  ** PROGRAMMING by: DEREK CRIBBS         Date:  03/18/93                      **
  3.  **                                                                           **
  4.  ** SndPlayMidi - simple function to play a midi file similar to sndplaysound **
  5.  ** for .WAV files.                                                           **
  6.  **                                                                           **
  7.  ** I wrote this little Unit to help BPW users like myself.                   **
  8.  ** Since I was looking for some code to do this before I wrote it, I figured **
  9.  ** the least I could do was save you all some time, by giving you a start    **
  10.  ** with my efforts, I used the multimedia programmers workbook for reference **
  11.  **                                                                           **
  12.  **                                                                           **
  13.  **   If (you like it) then                                                   **
  14.  **   begin                                                                   **
  15.  **     keep_it;                                                              **
  16.  **     use_it;                                                               **
  17.  **     pass_it_on;                                                           **
  18.  **   end                                                                     **
  19.  **   else                                                                    **
  20.  **     trash_it;                                                             **
  21.  **                                                                           **}
  22. unit midi;
  23. interface
  24. uses  wintypes,Winprocs,MMSystem,win31,strings;
  25. function SndPlayMidi(HWndNotify:Hwnd;lpszMIDIFilename:Pchar):LongInt;
  26. implementation
  27. function SndPlayMidi(HWndNotify:Hwnd;lpszMIDIFilename:Pchar):LongInt;
  28. type
  29.   MCI_OPEN_PARMS = TMCI_Open_Parms;
  30.   MCI_SET_PARMS  = TMCI_Set_Parms;
  31.     MCI_PLAY_PARMS = TMCI_Play_Parms;
  32.   MCI_STATUS_PARMS = TMCI_Status_Parms;
  33.   MCI_SEQ_SET_PARMS = TMCI_Seq_Set_Parms;
  34. var
  35.   wDeviceId:word;
  36.   dwReturn :LongInt;
  37.   mciOpenParms : MCI_OPEN_PARMS;
  38.   mciPlayParms : MCI_PLAY_PARMS;
  39.   mciStatusParms : MCI_STATUS_PARMS;
  40.   mciSeqSetParms : MCI_SEQ_SET_PARMS;
  41.   astring:string;
  42. begin
  43.   {choose midi sequencer}
  44.   mciOpenParms.lpstrDeviceType := 'SEQUENCER';
  45.   mciOpenParms.lpstrElementName:= lpszMIDIFileName;
  46.   Dwreturn:=mciSendCommand(0,MCI_OPEN,MCI_OPEN_TYPE or MCI_OPEN_ELEMENT,
  47.                       Longint(@MCIOPENPARMS));
  48.   wDeviceId:=MCIOPENPARMS.wDeviceId;
  49.   mciStatusParms.dwitem:=MCI_SEQ_STATUS_PORT;
  50.   DwReturn:=mciSendCommand(WDeviceID,MCI_STATUS,MCI_STATUS_ITEM,Longint(@MCISTATUSPARMS));
  51.   if DwReturn<>0 then
  52.   begin
  53.     mcisendcommand(wDeviceID,MCI_CLOSE,0,0);
  54.     SndPlayMidi:=dwReturn;
  55.   end;
  56.  
  57. { Uncomment this to check for MIDIMAPPER I just leave it commented for my purposes
  58.  
  59.   if LoWord(mciStatusParms.DwReturn) <> MIDIMAPPER then
  60.   begin
  61.     mciSendCommand(wDeviceID, MCI_CLOSE,0,0);
  62.     SndPlayMidi:=0;
  63.   end;}
  64.  
  65.   mciPlayParms.dwCallBack:=LongInt(hWndNotify);
  66.   DwReturn:=mciSendCommand(WDeviceID,MCI_PLAY,MCI_NOTIFY,Longint(@MCISTATUSPARMS));
  67.   if DwReturn<>0 then
  68.   begin
  69.     mcisendcommand(wDeviceID,MCI_CLOSE,0,0);
  70.     SndPlayMidi:=dwreturn;
  71.   end;
  72.   SndPlayMidi:=0;
  73. end;
  74. end.